<template>
	<view class="">
		<page-container :overlay="false" :show="isShowPage" @beforeleave="beforeleave"
			custom-style="height:100vh;overflow:scroll">
			<view class="box">
				<view class="flex box_head u-flex-between">
					<view class="box_head_title">
						门牌号{{big_sort}}-{{small_sort}}
					</view>
					<view class="box_head_name">
						{{familyname}}
					</view>
				</view>
				<view class="box_lists flex u-flex-between ">
					<view class="left">
						<view class="box_list" v-for="(i,v) in oneWord" :key="v" @click="open(i,v)"
							:class="current==i.xh?'hover':''">
							<view class="b_l_name u-line-1">
								{{i.xh}}.{{i.wordHead}}
								<image src="../../static/image/laodalaoda.png" mode="" v-if="current==i.xh"></image>
							</view>
							<view class="b_l_pro u-line-1">
								{{i.tran}}
							</view>
						</view>
					</view>
					<view class="right">
						<view class="box_list" v-for="(i,v) in twoWord" :key="v" @click="open(i,v)"
							:class="current==i.xh?'hover':''">
							<view class="b_l_name u-line-1">
								{{i.xh}}.{{i.wordHead}}
								<image src="../../static/image/laodalaoda.png" mode="" v-if="current==i.xh"></image>
							</view>
							<view class="b_l_pro u-line-1">
								{{i.tran}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="pos">
				<view class="warn flex flex-center">
					<image src="../../static/alarm-icon.png" mode="" class="warn_img"></image>
					<view class="warn_title">
						点击单词挑选该家老大，可进行关联记忆并提升记忆速度

					</view>
				</view>
				<view class="btn" @click="sure()">
					家老大选择确认
				</view>
			</view>
		</page-container>
		<up-popup :show="show" mode='center' bgColor='transparent'>
			<view class="popup_bg">
				<view class="popup_title">
					温馨提示
				</view>
				<view class="popup_pro">
					坚持就是胜利！若您要坚持退出 下次记忆将接着此次记录继续
				</view>
				<view class="flex u-flex-between padding-30 marginTop-15">
					<view class="popup_cancel" @click="cancel">
						退出
					</view>
					<view class="popup_sure" @click="confirm">
						继续学习
					</view>
				</view>
			</view>
		</up-popup>
		<up-popup :show="successShow" mode='center' bgColor='transparent'>
			<view class="popup_bg">
				<view class="popup_title">
					温馨提示
				</view>
				<view class="popup_pro">
					太棒啦！本阶段训练完成
				</view>
				<view class="flex u-flex-between padding-30 marginTop-15">
					<view class="popup_cancel" @click="zaici">
						再次训练
					</view>
					<view class="popup_sure" @click="nextClick">
						下阶段
					</view>
				</view>
			</view>
		</up-popup>
	</view>
</template>

<script setup>
	import {
		ref,
		inject,
		onMounted,
		reactive
	} from 'vue';
	import {
		onLoad,
		onUnload,
		onShareAppMessage
	} from '@dcloudio/uni-app';
	const page = ref(1)
	const successShow=ref(false)
	const big_sort = ref(1)
	const small_sort = ref(1)
	const show = ref(false)
	const isShowPage = ref(true)
	const english_story = ref('')
	const resultWordListApi = inject('resultWordList')
	const oneWord = ref([])
	const twoWord = ref([])
	const familyname = ref('')
	const current = ref(1)
	const id = ref('')
	onLoad((op) => {
		page.value = op.page
		small_sort.value = op.small_sort
		big_sort.value = op.big_sort
		resultWordListApi({
			page: page.value,
			small_sort: small_sort.value,
			big_sort: big_sort.value
		}).then(res => {
			console.log(res, 106)
			oneWord.value = res.oneWord
			twoWord.value = res.twoWord
			familyname.value = res.familyname
			id.value = res.oneWord[0].id
			res.oneWord.forEach((item,index)=>{
				if(item.is_biger==1){
					current.value=item.xh
				}
			})
			res.twoWord.forEach((item,index)=>{
				if(item.is_biger==1){
					current.value=item.xh
				}
			})
		})
	})
	// 离开出现的弹窗
	const beforeleave = (e) => {
		isShowPage.value = false
		show.value = true
	}
	const cancel = () => {
		uni.navigateBack()
	}
	const confirm = () => {
		isShowPage.value = true
		show.value = false
	}
	const open = (i, v) => {
		current.value = i.xh
		id.value = i.id
	}
	const zaici = () => {
		uni.redirectTo({
			url: '/pagesA/reciteWords/wordArea?page=' + page.value + "&small_sort=" + small_sort.value +
				'&big_sort=' + big_sort.value
		})
	}
	const nextClick = () => {
		uni.redirectTo({
			url: '/pagesA/reciteWords/wordDesc?big_sort=' + big_sort.value +
				'&page=' + page.value + '&small_sort=' + small_sort.value + '&step=3'
		})
	}
	
	const updateBigerApi = inject('updateBiger')
	const sure = () => {
		updateBigerApi({
			page: page.value,
			small_sort: small_sort.value,
			big_sort: big_sort.value,
			id: id.value
		}).then(res => {
			successShow.value=true
			// uni.redirectTo({
			// 	url: '/pagesA/reciteWords/wordDesc?big_sort=' + big_sort.value +
			// 		'&page=' + page.value + '&small_sort=' + small_sort.value + '&step=3'
			// })
		})

	}
</script>

<style scoped lang="scss">
	.popup_bg {
		width: 610rpx;
		height: 500rpx;
		background: url('https://bbsf.oss-cn-shanghai.aliyuncs.com/english/icons/remind.png') no-repeat;
		background-size: 100% 100%;

		.popup_title {
			font-family: PingFang SC, PingFang SC;
			font-weight: 800;
			font-size: 52rpx;
			color: #FFFFFF;
			text-align: center;
			padding-top: 20rpx;
		}

		.popup_pro {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 36rpx;
			color: #333333;
			line-height: 42rpx;
			text-align: center;
			font-style: normal;
			text-transform: none;
			width: 504rpx;
			height: 100rpx;
			margin: 120rpx auto 0;
		}

		.popup_cancel {
			width: 252rpx;
			height: 92rpx;
			background: #CCCCCC;
			border-radius: 74rpx 74rpx 74rpx 74rpx;
			text-align: center;
			line-height: 92rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 800;
			font-size: 32rpx;
			color: #FFFFFF;
		}

		.popup_sure {
			width: 252rpx;
			height: 92rpx;
			background: #51D580;
			border-radius: 74rpx 74rpx 74rpx 74rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 800;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 92rpx;
			text-align: center;
			font-style: normal;
			text-transform: none;
		}

		.popup_see {
			width: 526rpx;
			height: 92rpx;
			background: #51D580;
			border-radius: 74rpx 74rpx 74rpx 74rpx;
			text-align: center;
			line-height: 92rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 800;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 92rpx;
			text-align: center;
			font-style: normal;
			text-transform: none;
		}

	}

	.box {
		width: 710rpx;
		height: 1040rpx;
		background: #F4FFF8;
		margin: 40rpx auto;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		border: 12rpx solid #51D580;

		.box_head {
			padding: 30rpx 40rpx;

			.box_head_title {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 32rpx;
				color: #666666;
			}

			.box_head_name {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #666666;
			}
		}

		.box_lists {
			// padding: 0 104rpx;
			margin-top: 40rpx;

			.left,
			.right {
				width: 50%;
				padding-right: 10rpx;
			}

			.left {
				margin-left: 140rpx;

			}

			.box_list {
				margin-bottom: 80rpx;
				padding: 10rpx;

				// width: 50%;
				.b_l_name {
					font-family: PingFang SC, PingFang SC;
					font-weight: 800;
					font-size: 30rpx;
					color: #333333;

					image {
						width: 32rpx;
						height: 32rpx;
					}
				}

				.b_l_pro {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #666666;
				}
			}

			.hover {
				border: 4rpx solid #51D580;
				border-radius: 30rpx;
			}
		}

	}

	.pos {
		position: fixed;
		bottom: 36rpx;
		left: 24rpx;

		.warn {
			margin-bottom: 24rpx;

			.warn_img {
				width: 32rpx;
				height: 32rpx;
				margin-right: 4rpx;
			}

			.warn_title {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #999999;

				text {
					color: #DF2828;
				}
			}

		}

		.btn {
			width: 702rpx;
			height: 104rpx;
			background: #51D580;
			border-radius: 92rpx 92rpx 92rpx 92rpx;
			line-height: 104rpx;
			text-align: center;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 32rpx;
			color: #FFFFFF;
		}
	}

	@media (max-height: 800px) {
		.box {
			height: 850rpx;
		}
	}
</style>